package com.tanhua.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {


    // 根据类型+时间统计 用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE TYPE=#{type} AND log_time=#{today}")
    Integer selectNumByTypeAndTime(@Param("type") String type,@Param("today") String today);

    // 根据时间统计 用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE  log_time=#{today}")
    Integer selectNumByTime( String today);

    // 次日留存用户统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE log_time=#{today} \n" +
            "\tAND user_id IN (SELECT user_id FROM `tb_log` WHERE TYPE='0102' AND log_time=#{yesterday})")
    Integer findNumByRetention(@Param("today") String today ,@Param("yesterday") String yesterday);


}